<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of EditMyDataForm
 *
 * @author Mina
 */
class EditMyDataForm extends UserForm
{

    public function configure()
    {
        parent::configure();
        // add confirm password widget to compar passwords
        $this->setWidget('re_password', new sfWidgetFormInputPassword(array(), array('title' => 'Min=5', "class" => "tooltips")));
        $this->setValidator('re_password', new sfValidatorString(array('required' => $this->isNew())));

        // add compar password validator
        $this->mergePostValidator(new sfValidatorSchemaCompare(
                        'password', sfValidatorSchemaCompare::EQUAL, 're_password', array(), array('invalid' => 'Passwords not mached')
                )
        );
        $this->useFields(array('username', 'name', 'password', 're_password', 'email', 'phone', 'mobile', 'address', 'photo'));
    }

    public function doBind(array $values)
    {
        // in edit mode we need to check if user send password values or not
        if (!$this->isNew())
        {
            if (!$values['password'] && !$values['re_password'])
            {
                unset($this['password'], $this['re_password'], $values['password'], $values['re_password']);
            }
        }
        parent::doBind($values);
    }

}
